package com.example.card.abstracttransactions;


import com.example.card.CardConstant;
import com.example.card.domain.card.Card;
import com.example.card.domain.card.ExpireDataLimit;

public abstract class CardConsumptionTransaction extends CardModifyTransaction {

    protected final int amount;


    public CardConsumptionTransaction(int memberId, int id, int amount) {
        super(memberId, id);
        this.amount = amount;
    }

    public abstract void consumer(Card card);


    @Override
    public void change(Card card) {
        checkStatus(card.getStatus());
        checkExpireDate(card.getExpireDataLimit());
        consumer(card);
    }

    private boolean checkStatus(Integer status) {
        if (status != CardConstant.STATUS_NORMAL) {
            throw new RuntimeException("卡状态异常");
        }
        return true;
    }

    private boolean checkExpireDate(ExpireDataLimit expireDataLimit) {
        if (expireDataLimit.isExpire()) {
            throw new RuntimeException("卡表已过有效期");
        }

        return false;

    }

}
